<template>
  <div id="app">
      <div class="flex">
          <div class="flex-menu">
              <ul>
                  <li>
                      <div>组件</div>
                      <ul>
                          <li :class="{active:index === i}" v-for="(k,i) in componentsMenu" :key="i" @click="changeComponentsView(i)">{{k}}</li>
                      </ul>
                  </li>
                  <li>
                      <div>指令</div>
                      <ul>
                          <li :class="{active:index === i + componentsMenu.length}" v-for="(k,i) in directivesMenu" :key="i" @click="changeDirectivesView(i)">{{k}}</li>
                      </ul>
                  </li>
              </ul>
          </div>
          <div class="flex-content" ref="content">
              <div class="content">
                  <component :is="view"></component>
              </div>
          </div>
      </div>
  </div>
</template>

<script>
import ccJsonViewDemo from './demo/ccJsonViewDemo'
import ccAnchorDemo from './demo/ccAnchorDemo'
import ccDragDemo from './demo/ccDragDemo'

export default {
  name: 'App',
  components: {
      ccJsonViewDemo,
      'v-cc-anchorDemo': ccAnchorDemo,
      'v-cc-dragDemo': ccDragDemo,
  },
  data() {
      return {
          view: '',
          index: 0,
          componentsMenu: ['ccJsonView'],
          directivesMenu: ['v-cc-anchor', 'v-cc-drag'],
      }
  },
    watch: {
      view() {
          this.$refs.content.scrollTo(0, 0);
      }
    },
    methods: {
      changeComponentsView(i) {
          this.index = i;
          this.view = this.componentsMenu[i] + 'Demo';
      },
        changeDirectivesView(i) {
            this.index = i + this.componentsMenu.length;
            this.view = this.directivesMenu[i] + 'Demo';
        }
    },
    created() {
      this.changeComponentsView(0);
    }
}
</script>

<style lang="scss">
    html, body {
        margin: 0;
        padding: 0;
    }
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}
.code {
    display: inline-block;
    background: #eee;
    padding: 5px;
    border-radius: 5px;
    font-size: 12px;
    margin: 0 5px;
}
.tips {
    border-left: 4px solid #3087ff;
    font-size: 14px;
    padding: 10px;
    margin: 5px 0;
    background: #f1f1f1;
}
.attr {
    color: #c00;
}
    .title {
        font-weight: bold;
        font-size: 15px;
        margin: 5px 0;
    }
    .desc {
        font-size: 14px;
    }
table {
    border-collapse: collapse;
    border: 1px solid #eee;
    font-size: 14px;
    width: 100%;
    text-align: left;

    caption {
        text-align: left;
        font-weight: bold;
        padding: 5px;
    }
    td, th {
        border: 1px solid #eee;
        padding: 5px;
    }
}
    .flex {
        display: flex;
        height: 100vh;
        overflow: hidden;
        .flex-menu {
            width: 200px;
            background: #eee;
            height: 100vh;
            overflow: auto;
            flex-shrink: 0;
            font-size: 14px;
            li {
                cursor: pointer;
                padding: 5px 0;
            }
            li.active {
                font-weight: bold;
                color: #48a4ff;
            }
        }
        .flex-content {
            overflow: auto;
            flex-grow: 1;
            min-height: 100vh;
            .content {
                padding: 20px;
            }
        }
    }
</style>
